package cn.jee.spring_jdbc.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import javax.sql.DataSource;

@Repository("stuDao")
public class StuDaoImp implements StuDao{
    private JdbcTemplate jdbcTemplate;
    @Autowired
    public void setDataSource(DataSource dataSource){
        this.jdbcTemplate=new JdbcTemplate(dataSource);
    }
    @Transactional
    @Override
    public void tx() {
        jdbcTemplate.update("insert into stu(username, java) values('tx-1',90)");
        throw new RuntimeException("测试事务");
    }
}